clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

******************************************************************************************
********************************** Figure S6: Placebo test
******************************************************************************************

************************* Poverty
use "${date}/_data/spid_for_analysis_v2.dta", clear
encode geo_code2_new, gen(id_region)
keep id_region year temp
duplicates drop id_region year, force
save "${date}/_data/placebo/region_year.dta", replace

use "${date}/_data/placebo/region_year.dta", clear
keep id_region
duplicates drop id_region, force
save "${date}/_data/placebo/region.dta", replace
clear
forval i=1/1000 {
	use "${date}/_data/placebo/region_year.dta", clear
	rename id_region id_region_placebo`i'
	rename temp temperature_pc`i'
	save "${date}/_data/placebo/region_year`i'.dta", replace
}

forval i=1/1000 {
use "${date}/_data/placebo/region.dta", clear
gen id = _n
set seed `i'
capture drop scramble 
gen scramble = runiform()
sort scramble
capture drop id_random
gen id_random = _n

gen id_region_placebo`i' = id_region[id]

sort id_region
	merge 1:m id_region using "${date}/_data/placebo/region_year.dta"
	keep if _merge==3
	drop _merge

sort id_region_placebo`i' year
	merge 1:m id_region_placebo`i' year using "${date}/_data/placebo/region_year`i'.dta"
	drop if _merge==2
	drop _merge
	
save "${date}/_data/placebo/temp_placebo`i'.dta", replace
}

use "${date}/_data/spid_for_analysis_v2.dta", clear
encode geo_code2_new, gen(id_region)
local controls ln_GDPppp Unempilo agri manuf popgr 

capture drop placebo_mu
gen placebo_mu = .

capture drop placebo_t
gen placebo_t = .

postfile store b se using "${date}/_data/placebo/placebo1.dta", replace
forval i=1/1000 {
sort id_region year
	merge m:1 id_region year using "${date}/_data/placebo/temp_placebo`i'.dta"
	drop _merge
	qui reghdfe poor215 temperature_pc`i' rainfall_sum humid `controls', absorb(id_region year) cluster(id_region) keepsingle	
		post store (_b[temperature_pc`i']) (_se[temperature_pc`i'])
	drop temperature_pc`i'
}		
postclose store	

// TRUE ESTIMATE & T-STATISTOCS
use "${date}/_data/spid_for_analysis_v2.dta", clear

local controls ln_GDPppp Unempilo agri manuf popgr 
reghdfe poor215 temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	

gen b = _b[temp]			// 0.629
gen se = _se[temp]		// 0.125
gen t= b/se					// 5.05

use "${date}/_data/placebo/placebo1.dta", clear
	
gen t= b/se

histogram t, width() xline(5.05, lpattern(dash)) xlabel(-1.960 "-1.96" 0 1.960 "1.96" 5.05 "5.05", labsize(vsmall)) ///
	xtitle(t-statistic) percent lwidth(none) color(gs5) graphregion(color(white)) bgcolor(white) ///
	ylabel(, nogrid)  text(6 4 "Non-placebo t-statistic", size(small)) saving(placebo1, replace)

histogram b, width() xline(0.629, lpattern(dash)) xlabel(0.629 "0.629" -0.5 0 0.5, labsize(vsmall)) ///
	xtitle(Coefficient) percent lwidth(none) color(gs5) graphregion(color(white)) ///
	bgcolor(white)  ylabel(, nogrid) text(7 0.6 "Non-placebo coefficient", size(small)) saving(placebo2, replace)

graph combine placebo1.gph placebo2.gph,rows(2) scheme(s1mono)
   
graph export "${date}/_figures/_fig_s6a.pdf", as(pdf) replace	


************************* Inequality
use "${date}/_data/spid_for_analysis_v2.dta", clear
encode geo_code2_new, gen(id_region)
keep id_region year temp
duplicates drop id_region year, force
save "${date}/_data/placebo/region_year.dta", replace

use "${date}/_data/placebo/region_year.dta", clear
keep id_region
duplicates drop id_region, force
save "${date}/_data/placebo/region.dta", replace
clear
forval i=1/1000 {
	use "${date}/_data/placebo/region_year.dta", clear
	rename id_region id_region_placebo`i'
	rename temp temperature_pc`i'
	save "${date}/_data/placebo/region_year`i'.dta", replace
}

forval i=1/1000 {
use "${date}/_data/placebo/region.dta", clear
gen id = _n
set seed `i'
capture drop scramble 
gen scramble = runiform()
sort scramble
capture drop id_random
gen id_random = _n

gen id_region_placebo`i' = id_region[id]

sort id_region
	merge 1:m id_region using "${date}/_data/placebo/region_year.dta"
	keep if _merge==3
	drop _merge

sort id_region_placebo`i' year
	merge 1:m id_region_placebo`i' year using "${date}/_data/placebo/region_year`i'.dta"
	drop if _merge==2
	drop _merge
	
save "${date}/_data/placebo/temp_placebo`i'.dta", replace
}

use "${date}/_data/spid_for_analysis_v2.dta", clear
encode geo_code2_new, gen(id_region)
local controls ln_GDPppp Unempilo agri manuf popgr 

capture drop placebo_mu
gen placebo_mu = .

capture drop placebo_t
gen placebo_t = .

postfile store b se using "${date}/_data/placebo/placebo1.dta", replace
forval i=1/1000 {
sort id_region year
	merge m:1 id_region year using "${date}/_data/placebo/temp_placebo`i'.dta"
	drop _merge
	qui reghdfe gini temperature_pc`i' rainfall_sum humid `controls', absorb(id_region year) cluster(id_region) keepsingle	
		post store (_b[temperature_pc`i']) (_se[temperature_pc`i'])
	drop temperature_pc`i'
}		
postclose store	

// TRUE ESTIMATE & T-STATISTOCS
use "${date}/_data/spid_for_analysis_v2.dta", clear

local controls ln_GDPppp Unempilo agri manuf popgr 

reghdfe gini temp rainfall_sum humid `controls', absorb(geo_code2_new year) cluster(geo_code2_new) keepsingle	

gen b = _b[temp]			// 0.463
gen se = _se[temp]		// 0.140
gen t= b/se					// 3.31

use "${date}/_data/placebo/placebo1.dta", clear
	
gen t= b/se

histogram t, width() xline(3.31, lpattern(dash)) xlabel(3.31 "3.31" -1.960 "-1.96" 0 1.960 "1.96", labsize(vsmall)) ///
	xtitle(t-statistic) percent lwidth(none) color(gs5) graphregion(color(white)) bgcolor(white) ///
	ylabel(, nogrid)  text(6 3 "Non-placebo t-statistic", size(small)) saving(placebo1, replace)

histogram b, width() xline(0.463, lpattern(dash)) xlabel(0.463 "0.463" -0.5 0 , labsize(vsmall)) ///
	xtitle(Coefficient) percent lwidth(none) color(gs5) graphregion(color(white)) ///
	bgcolor(white)  ylabel(, nogrid) text(7 0.6 "Non-placebo coefficient", size(small)) saving(placebo2, replace)

graph combine placebo1.gph placebo2.gph,rows(2) scheme(s1mono)
   
graph export "${date}/_figures/_fig_s6b.pdf", as(pdf) replace	
